package com.wx.tgp.socket.demo.thread;


import org.apache.log4j.Logger;

import javax.xml.bind.DatatypeConverter;
import java.io.FileInputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;

/**
 * 线程的回调函数
 */
public class CallbackDigest implements Runnable {

    Logger log = Logger.getLogger(CallbackDigest.class);

    private String fileName;

    public CallbackDigest(String fileName){
        this.fileName = fileName;
    }

    @Override
    public void run() {
        try{
            FileInputStream fis = new FileInputStream(fileName);
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            DigestInputStream dis = new DigestInputStream(fis,md);
            while(dis.read()!=-1){
//                log.info(dis.read());
            };
            dis.close();
            byte[] digest = md.digest();
//            CallbackDigestUserInterface   CallbackDigestUserInterface
            CallbackDigestUserInterface.callbackDigest(digest,fileName);
        }catch (Exception e){
            log.error(e.getMessage());
            e.printStackTrace();
        }
    }
}
